package com.cwf.quality.common.strategy.factory;

import com.cwf.quality.common.enums.DataCheckFilterEnum;
import com.cwf.quality.common.strategy.filter.IDataCheckFilter;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class DataCheckFilterFactory {
    private static Map<String, IDataCheckFilter> dataCheckFilterMap = new HashMap<>();

    static {
        for (DataCheckFilterEnum dataCheckFilterEnum : DataCheckFilterEnum.values()) {
            try {
                Class<?> clazz = Class.forName(dataCheckFilterEnum.getClassName());
                IDataCheckFilter iDataCheckFilter = (IDataCheckFilter) clazz.newInstance();
                dataCheckFilterMap.put(dataCheckFilterEnum.getType(), iDataCheckFilter);
            } catch (ClassNotFoundException e) {
                log.error(e.getMessage(), e);
            } catch (IllegalAccessException e) {
                log.error(e.getMessage(), e);
            } catch (InstantiationException e) {
                log.error(e.getMessage(), e);
            }
        }
    }

    public static IDataCheckFilter getDataCheckFilter(String dataCheckFilterType) {
        return dataCheckFilterMap.get(dataCheckFilterType);
    }
}
